﻿//-----------------------------------------------------------------------
// <copyright file="AuthorizationServiceBase.cs" company="Alan Rodrigues">
//     Copyright (c) Alan Rodrigues. All rights reserved.
// </copyright>
// <developed>Alan Rodrigues (operninha@gmail.com)</developed>
//-----------------------------------------------------------------------

namespace Authorization
{
    using System;
    using Properties;

    public partial class AuthorizationServiceBase
    {

      #region Applications
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ApplicationCollection GetAllApplications()
        {
            return AuthorizationStoreManager.GetApplications();
        }

        public string[] GetAllApplicationNames()
        {
            return AuthorizationStoreManager.GetApplicationNames();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="applicationName"></param>
        /// <returns></returns>
        public Application GetApplication(string applicationName)
        {
            return AuthorizationStoreManager.GetApplication(applicationName);
        }

        public bool ApplicationExists(string applicationName)
        {
            SecUtility.CheckParameter(ref applicationName, true, true, false, 64, "applicationName");
            return AuthorizationStoreManager.ApplicationExists(applicationName);
        }



        public void DeleteApplication(string applicationName)
        {
          SecUtility.CheckParameter(ref applicationName, true, true, false, 64, "applicationName");
          var store =  AuthorizationStoreManager.DeleteApplication(applicationName);
          store.Save();
        }

        public Application CreateApplication(string storeName, string applicationName, string version, string Description, string applicationData)
        {
            SecUtility.CheckParameter(ref applicationName, true, true, false, 64, "applicationName");

          var application =  AuthorizationStoreManager.CreateApplication(storeName, applicationName, version, Description, applicationData);

          application.Save();
          return application;
        }


        public Application UpdateApplication(string applicationName, string newApplicationName, string newVersion, string newDescription, string newApplicationData)
        {
            SecUtility.CheckParameter(ref applicationName, true, true, false, 64, "applicationName");

            var application = AuthorizationStoreManager.UpdateApplication(applicationName, newApplicationName, newVersion, newDescription, newApplicationData);
            application.Save();
            return application;
        }

        #endregion
    }
}
